<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ include file="global.jsp" %>
<%
if(request.getParameter("comments")!=null && !("").equals(request.getParameter("comments"))){
String success = "";
DateFormat formater = new SimpleDateFormat("ddMMM HH:mm:ss");
java.util.Date sysDate = new java.util.Date();
String dateFormat = formater.format(sysDate);
try{
	Class.forName(db_driver);
	Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
	String query = "insert into comments(chatUser, comments, dateFormat, league) values(?, ?, ?, ?)";
	String userName = (String) session.getAttribute("userName");
	String league = (String) session.getAttribute("league");
	if(null == league){
		league = "General";
	}
	System.out.println("Commented IP: "+request.getRemoteAddr()+":::"+request.getParameter("comments"));
	if(userName == null || ("").equals(userName)){
		userName= "unknown";
	}
	PreparedStatement pstmt = conn.prepareStatement(query); // create a statement
	pstmt.setString(1, userName);// set input parameter 1
	pstmt.setString(2, request.getParameter("comments")); // set input parameter 2
	pstmt.setString(3, dateFormat);
	pstmt.setString(4, league);
	pstmt.executeUpdate();
	pstmt.close();	
	conn.close();
	success ="Updated Succesfully";
	} 
	 catch (Exception e){
	      e.printStackTrace();
	      success ="Failure in insertion";
	} 
}
response.sendRedirect("chat.jsp");
%>
